package com.yssw.client.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sun.jna.platform.win32.Variant;
import com.yssw.client.domain.vo.EditBalanceVO;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yssw.common.annotation.Log;
import com.yssw.common.core.controller.BaseController;
import com.yssw.common.core.domain.AjaxResult;
import com.yssw.common.enums.BusinessType;
import com.yssw.client.domain.RechargeRecord;
import com.yssw.client.service.IRechargeRecordService;
import com.yssw.common.utils.poi.ExcelUtil;
import com.yssw.common.core.page.TableDataInfo;

/**
 * 充值记录Controller
 *
 * @author ice
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/client/rechargeRecord")
public class RechargeRecordController extends BaseController {
    @Autowired
    private IRechargeRecordService rechargeRecordService;

    /**
     * 查询充值记录列表
     */
    @PreAuthorize("@ss.hasPermi('client:rechargeRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(RechargeRecord rechargeRecord) {
        startPage();
        List<RechargeRecord> list = rechargeRecordService.selectRechargeRecordList(rechargeRecord);
        return getDataTable(list);
    }

    /**
     * 导出充值记录列表
     */
    @PreAuthorize("@ss.hasPermi('client:rechargeRecord:export')")
    @Log(title = "充值记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RechargeRecord rechargeRecord) {
        List<RechargeRecord> list = rechargeRecordService.selectRechargeRecordList(rechargeRecord);
        ExcelUtil<RechargeRecord> util = new ExcelUtil<RechargeRecord>(RechargeRecord.class);
        util.exportExcel(response, list, "充值记录数据");
    }

    /**
     * 获取充值记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('client:rechargeRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rechargeRecordService.selectRechargeRecordById(id));
    }

    /**
     * 新增充值记录
     */
    @PreAuthorize("@ss.hasPermi('client:rechargeRecord:add')")
    @Log(title = "充值记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RechargeRecord rechargeRecord) {
        return success(rechargeRecordService.insertRechargeRecord(rechargeRecord));
    }

    /**
     * 修改充值记录
     */
    @PreAuthorize("@ss.hasPermi('client:rechargeRecord:edit')")
    @Log(title = "充值记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RechargeRecord rechargeRecord) {
        return toAjax(rechargeRecordService.updateRechargeRecord(rechargeRecord));
    }

    /**
     * 删除充值记录
     */
    @PreAuthorize("@ss.hasPermi('client:rechargeRecord:remove')")
    @Log(title = "充值记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rechargeRecordService.deleteRechargeRecordByIds(ids));
    }

    /**
     * 修改充值记录状态，添加用户余额
     */
    @PreAuthorize("@ss.hasPermi('client:rechargeRecord:edit')")
    @Log(title = "充值记录",businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult editStatusAndBalance(@RequestBody EditBalanceVO editBalanceVO) {
        if(ObjectUtils.isEmpty(editBalanceVO)) {
            return AjaxResult.error("参数不能为空！");
        }
        return toAjax(rechargeRecordService.editStatusAndBalance(editBalanceVO));
    }
}
